package org.alex.samples.dao;

import java.util.List;

import org.alex.samples.model.ExamScoreVO;
import org.alex.samples.model.ExamTest;
import org.hibernate.transform.Transformers;
import org.hibernate.type.StringType;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional
public class ExamTestDAOImpl extends BaseHibernateDAO<ExamTest> implements IExamTestDAO {
	
	@Override
	public List<ExamTest> findAllExamTests() {
		String hql="from ExamTest";
		List<ExamTest> examList = this.find(hql);
		return examList;
	}

	@Override
	public ExamTest getExamTestById(Integer id) {
		ExamTest exsitsExamTest = this.get(id);
		return exsitsExamTest;
	}

	@Override
	public void createExamTest(ExamTest examTest) throws Exception {
			this.save(examTest);
	}

	@Override
	public void editExamTest(ExamTest examTest) throws Exception {
			this.update(examTest);
	}

	@Override
	public void deleteExamTest(Integer id) throws Exception {
		ExamTest exsitsExamTest = this.get(id);
		if(exsitsExamTest!=null){
			this.delete(exsitsExamTest);
		}
	}

	
	@Override
	public List<ExamTest> getTestListBySubAndTestType(Integer subId, Integer id) {
		String hql = "from ExamTest where subject.id=" + subId;
		return this.find(hql);
		
	}
	@Override
	public List<ExamTest> getTestListBySubAndTestTypeExample(Integer subId) {
		String hql = "from ExamTest where subject.id=" + subId;
		return this.find(hql);
		
	}

	@Override
	public List<ExamTest> getTestListByIdList(List<Integer> randomTestIdList) {
		// TODO Auto-generated method stub
		return null;
	}

}


//@Autowired
//private SessionFactory sessionFactory;
//
//public Session getSession(){
//	return this.sessionFactory.getCurrentSession();
//}

//Session session = getSession();
//String hql="from ExamTest";
//@SuppressWarnings("unchecked")
//List<ExamTest> examList = session.createQuery(hql).list();

//Session session =getSession();
//return (ExamTest) session.get(ExamTest.class, id);

//Session session = getSession();
//session.save(examTest);

//Session session = getSession();
//session.update(examTest);

//Session session = getSession();
//ExamTest exsitsExamTest = (ExamTest) session.get(ExamTest.class, id);
//if(exsitsExamTest !=null){
//	session.delete(exsitsExamTest);
//}
